package com.scalar.chiptrack.operations.wipflush.actioncommands;

import com.scalar.chiptrack.actioncommands.ActionCommand;
import com.scalar.chiptrack.users.User;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.process.dao.ProductDao;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * User: Administrator
 * Date: Oct 24, 2005
 * Time: 1:46:38 PM
 */
public class WipFlushSetupSearchCommand extends ActionCommand
{
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        ActionForward actionForward = mapping.findForward( "success" );
        HttpSession session = request.getSession();
        HashMap errors = new HashMap ();
        request.setAttribute ( SessionKeys.ERROR_MESSAGES, errors );
        User pUser = ( User )session.getAttribute( SessionKeys.USER_KEY );
        String userId = pUser.getUserId();
        try
        {
            ArrayList baseProductList = ProductDao.loadChipBaseProducts( null );
            if ( baseProductList != null && baseProductList.size() > 0 )
            {
                request.setAttribute( "BaseProductList", baseProductList );
            }
            else
            {
                errors.put( "Could not find Base Products", null);
            }
        }
        catch ( Exception e )
        {
            errors.put( SessionKeys.ERROR_REPORT_SUBJECT, "Error: Could not find Base Products details");
            errors.put( SessionKeys.ERROR_REPORT, e );
        }
        return actionForward;
    }
}
